package com.yyfax.pay.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.yyfax.framework.yyfax.BaseEnum;

/**
 * 代付步骤枚举
 * 
 * @author maojian
 * @date 2017-04-18 11:16:33
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public final class PayinBatchStepEnum extends BaseEnum<String> {

	/** 枚举集合 */
	protected static final Map<String, PayinBatchStepEnum> values = new HashMap<>();

	public static final String ENUM_KEY = "PAYIN_STEP";

	public static final PayinBatchStepEnum STEP1_SUBMIT_ORDER = PayinBatchStepEnum.build("STEP1_SUBMIT_ORDER", "1", "请求支付");
	public static final PayinBatchStepEnum STEP2_PAY_RESULT = PayinBatchStepEnum.build("STEP2_PAY_RESULT", "2", "同步结果");
	public static final PayinBatchStepEnum STEP3_PAY_QUERY = PayinBatchStepEnum.build("STEP3_PAY_ASYN_RESULT", "3", "主动查询结果");
	public static final PayinBatchStepEnum STEP4_PAY_ASYN_RESULT = PayinBatchStepEnum.build("STEP4_PAY_ASYN_RESULT", "4", "异步结果");
	public static final PayinBatchStepEnum STEP5_PAY_RECON_RESULT = PayinBatchStepEnum.build("STEP5_PAY_RECON_RESULT", "5", "对账结果");
	public static final PayinBatchStepEnum STEP6_NOTIFY = PayinBatchStepEnum.build("STEP6_NOTIFY", "6", "通知商户结果");

	/**
	 * 构造函数
	 */
	private PayinBatchStepEnum(String name, String value, String remark) {
		super(name, value, remark);
	}

	public static List<PayinBatchStepEnum> values() {
		return new ArrayList<PayinBatchStepEnum>(values.values());
	}

	/**
	 * 不存在则添加,存在则更新(用于数据库加载时)
	 * 
	 * @author maojian
	 * @date 2016-12-05 19:31:30
	 * @param name
	 * @param value
	 * @param remark
	 * @return
	 */
	public static final PayinBatchStepEnum build(String name, String value, String remark) {
		PayinBatchStepEnum e = values.get(name);
		if (e == null) {
			e = new PayinBatchStepEnum(name, value, remark);
			values.put(name, e);
		} else {
			e.value = value;
			e.remark = remark;
		}
		return e;
	}

	public static final PayinBatchStepEnum fromValue(String value) {
		for (PayinBatchStepEnum e : values.values()) {
			if (StringUtils.equals(value, e.getValue())) {
				return e;
			}
		}
		return null;

	}
}
